package hit.edu.zjc.Operator;

import hit.edu.zjc.Tool.ObjectConvert;
import hit.edu.zjc.Tool.RWObject;
import hit.edu.zjc.Tool.ShowOutPut;
import hit.edu.zjc.UserInterface.UserDef;
import hit.edu.zjc.test.OperatorObjectRW;

import java.io.UnsupportedEncodingException;
import java.nio.ByteBuffer;
import java.util.Random;

import edu.uci.ics.hyracks.api.context.IHyracksTaskContext;
import edu.uci.ics.hyracks.api.dataflow.IOperatorNodePushable;
import edu.uci.ics.hyracks.api.dataflow.value.IRecordDescriptorProvider;
import edu.uci.ics.hyracks.api.dataflow.value.ISerializerDeserializer;
import edu.uci.ics.hyracks.api.dataflow.value.RecordDescriptor;
import edu.uci.ics.hyracks.api.exceptions.HyracksDataException;
import edu.uci.ics.hyracks.api.job.JobSpecification;
import edu.uci.ics.hyracks.dataflow.common.comm.io.ArrayTupleBuilder;
import edu.uci.ics.hyracks.dataflow.common.comm.io.FrameTupleAccessor;
import edu.uci.ics.hyracks.dataflow.common.comm.io.FrameTupleAppender;
import edu.uci.ics.hyracks.dataflow.common.comm.util.FrameUtils;
import edu.uci.ics.hyracks.dataflow.common.data.marshalling.Integer64SerializerDeserializer;
import edu.uci.ics.hyracks.dataflow.common.data.marshalling.IntegerSerializerDeserializer;
import edu.uci.ics.hyracks.dataflow.common.data.marshalling.UTF8StringSerializerDeserializer;
import edu.uci.ics.hyracks.dataflow.std.base.AbstractSingleActivityOperatorDescriptor;
import edu.uci.ics.hyracks.dataflow.std.base.AbstractUnaryInputUnaryOutputOperatorNodePushable;
/*
 * This Class AFK
 * */
public class TestOperatorDescriptor extends AbstractSingleActivityOperatorDescriptor {

    private static final long serialVersionUID = 1L;
    public TestOperatorDescriptor(JobSpecification spec) {
        super(spec, 1, 0);//输入输出端的数量。
        //Test
        //recordDescriptors[0] = new RecordDescriptor(new ISerializerDeserializer[]{UTF8StringSerializerDeserializer.INSTANCE});//输出数据的格式。
    }

    @Override
    public IOperatorNodePushable createPushRuntime(final IHyracksTaskContext ctx,
            IRecordDescriptorProvider recordDescProvider, int partition, int nPartitions) throws HyracksDataException {

      //  final FrameTupleAccessor accessor = new FrameTupleAccessor(ctx.getFrameSize(), new RecordDescriptor(DataISD_array));

        return new AbstractUnaryInputUnaryOutputOperatorNodePushable() {

            private ArrayTupleBuilder tupleBuilder;

            private ByteBuffer outputBuffer;

            private FrameTupleAppender outputAppender;

            @Override
            public void open() throws HyracksDataException {
                ShowOutPut.show("TestOperatorDescriptor Opened!");
                //writer.open();

            }

            @Override
            public void nextFrame(ByteBuffer buffer) throws HyracksDataException {
            		ShowOutPut.show("TestOperatorDescriptor nextFrame!");
               
            }

            @Override
            public void fail() throws HyracksDataException {
            	ShowOutPut.show("!!!!!!!!!Fail!!!!!!");
            	}

            @Override
            public void close() throws HyracksDataException {
            	ShowOutPut.show("TestOperatorDescriptor closed.");
                //writer.close();
            }
        };
    }
}